package com.bonc.service.impl;

import com.bonc.entity.Employee;
import com.bonc.mapper.EmployeeMapper;
import com.bonc.service.EmployeeService;
import com.bonc.vo.ResultVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author lenovo
 * @Title
 * @Description
 * @date 2021/7/27 11:26
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public ResultVO updateEmployee(Employee employee) {
        Integer updateNum = employeeMapper.updateEmployee(employee);
        return ResultVO.success("success", updateNum);
    }

    @Override
    public ResultVO findById(Integer id) throws Exception {
        return ResultVO.success(employeeMapper.findById(id), "success");
    }

    @Override
    public ResultVO findByPage(Map<String, Object> paramMap) {
        Integer pageNum = (Integer) paramMap.get("pageNum") == null ? 1 : (Integer) paramMap.get("pageNum");
        Integer pageSize = (Integer) paramMap.get("pageSize");
        PageHelper.startPage(pageNum, pageSize);
        List<Employee> employeeList = employeeMapper.findByEmployeeName((String) paramMap.get("employeeName"));
        PageInfo<Employee> pageInfo = new PageInfo<>(employeeList);
        int pages = pageInfo.getPages();
        long total = pageInfo.getTotal();
        return ResultVO.success(pageInfo, "success", pages);
    }


}
